Skip to content

Improve component search performance with JDBI#1867

Merged
nscuro merged 22 commits intomainfrom
issue-2049-improve-component-search-performance
Apr 15, 2026
Merged

Improve component search performance with JDBI#1867
nscuro merged 22 commits intomainfrom
issue-2049-improve-component-search-performance

Conversation

@sahibamittal
Copy link
Copy Markdown
Collaborator

@sahibamittal sahibamittal commented Mar 11, 2026

Description

  1. This change converts the SQL to single and optimised JDBI query for searching component by identity.
  2. Introduces new API endpoint to search components by identity under v2.
    Old and existing: /api/v1/component/identity
    New: /api/v2/components

Addressed Issue

Closes DependencyTrack/hyades#2049

Additional Details

Frontend changes: DependencyTrack/hyades-frontend#438

Checklist

  • I have read and understand the contributing guidelines
  • This PR fixes a defect, and I have provided tests to verify that the fix is effective
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have updated the migration changelog accordingly
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly

@sahibamittal sahibamittal marked this pull request as ready for review March 11, 2026 16:03
Comment thread api/src/main/openapi/openapi.yaml Outdated
Comment thread api/src/main/openapi/components/schemas/dependency-metrics.yaml Outdated
Comment thread api/src/main/openapi/components/schemas/component-project.yaml
Comment thread apiserver/src/main/java/org/dependencytrack/resources/v2/ComponentsResource.java Outdated
@sahibamittal sahibamittal requested a review from nscuro March 20, 2026 16:19
@sahibamittal sahibamittal requested a review from nscuro March 26, 2026 14:39
Comment thread apiserver/src/main/java/org/dependencytrack/persistence/jdbi/ComponentDao.java Outdated
Comment thread apiserver/src/main/java/org/dependencytrack/persistence/jdbi/ComponentDao.java Outdated
Comment thread apiserver/src/main/java/org/dependencytrack/persistence/jdbi/ComponentDao.java Outdated
Comment thread api/src/main/openapi/components/schemas/component-project.yaml Outdated
@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Mar 31, 2026

Up to standards ✅

🟢 Issues 2 medium

Results:
2 new issues

Category Results
Complexity 2 medium

View in Codacy

🟢 Metrics 100 complexity

Metric Results
Complexity 100

View in Codacy

🟢 Coverage 73.03% diff coverage · -0.51% coverage variation

Metric Results
Coverage variation -0.51% coverage variation (-1.00%)
Diff coverage 73.03% diff coverage (70.00%)

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (1fc7e2a) Report Missing Report Missing Report Missing
Head commit (4305f10) 42700 (+13899) 35892 (+11536) 84.06% (-0.51%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#1867) 241 176 73.03%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

TIP This summary will be updated as you push new changes. Give us feedback

@sahibamittal sahibamittal requested a review from nscuro March 31, 2026 16:24
@nscuro nscuro added this to the 5.7.0 milestone Apr 14, 2026
@nscuro nscuro added the enhancement New feature or request label Apr 14, 2026
Comment thread apiserver/src/main/java/org/dependencytrack/persistence/jdbi/ComponentDao.java Outdated
Comment thread apiserver/src/main/java/org/dependencytrack/persistence/jdbi/ComponentDao.java Outdated
Comment thread apiserver/src/main/java/org/dependencytrack/persistence/jdbi/ComponentDao.java Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new v2 components listing/search endpoint backed by an optimized JDBI query, aiming to improve component identity search performance and expand response data (project + metrics).

Changes:

  • Added GET /api/v2/components with filtering, sorting, and keyset pagination implemented via ComponentDao.listComponents(...).
  • Extended v2 API models/mapping to include project info and dependency metrics in component responses.
  • Updated OpenAPI definitions and tests, and introduced dedicated schemas for project-components listing responses.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
apiserver/src/test/java/org/dependencytrack/resources/v2/ComponentsResourceTest.java Adds test coverage for /api/v2/components pagination, sorting, filtering, ACL behavior, and error cases.
apiserver/src/test/java/org/dependencytrack/resources/v1/ComponentResourceTest.java Fixes a test bug setting PURL on the wrong component instance.
apiserver/src/main/java/org/dependencytrack/resources/v2/mapping/ModelMapper.java Adds mapping helpers for ComponentProject and DependencyMetrics.
apiserver/src/main/java/org/dependencytrack/resources/v2/WorkflowsResource.java Exposes a sort-direction converter (now reused elsewhere).
apiserver/src/main/java/org/dependencytrack/resources/v2/ProjectsResource.java Switches project-components listing response types to new ListProjectComponentsResponse* models.
apiserver/src/main/java/org/dependencytrack/resources/v2/ComponentsResource.java Implements listComponents endpoint using JDBI, with input parsing/validation and mapping to v2 models.
apiserver/src/main/java/org/dependencytrack/persistence/jdbi/PaginationSupport.java Adds bounded-total-count helper that can apply the API project ACL condition.
apiserver/src/main/java/org/dependencytrack/persistence/jdbi/ComponentDao.java Adds the optimized JDBI query + pagination logic for listing/searching components (plus optional metrics loading).
api/src/main/openapi/paths/projects_uuid_components.yaml Updates response schema reference for project components listing.
api/src/main/openapi/paths/components.yaml Adds OpenAPI definition for GET /components (v2) with filtering/sorting/pagination.
api/src/main/openapi/components/schemas/list-project-components-response.yaml New paginated schema for project components listing.
api/src/main/openapi/components/schemas/list-project-components-response-item.yaml New response-item schema for project components listing.
api/src/main/openapi/components/schemas/list-components-response-item.yaml Extends components list item schema with project and metrics; removes occurrence_count.
api/src/main/openapi/components/schemas/dependency-metrics.yaml Adds schema for dependency metrics.
api/src/main/openapi/components/schemas/component-project.yaml Adds schema for embedding project info in component responses.
Comments suppressed due to low confidence (1)

apiserver/src/main/java/org/dependencytrack/resources/v2/WorkflowsResource.java:289

  • Making convert(SortDirection) public on this resource appears to be only to support reuse from other resources (e.g., components). To avoid exposing resource-internal helpers as API surface, consider moving this mapping into a small shared utility class (or into the pagination/common layer) and keep this method private here.
    public static org.dependencytrack.common.pagination.@Nullable SortDirection convert(
            @Nullable SortDirection sortDirection) {
        return switch (sortDirection) {
            case ASC -> org.dependencytrack.common.pagination.SortDirection.ASC;
            case DESC -> org.dependencytrack.common.pagination.SortDirection.DESC;
            case null -> null;
        };

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/src/main/openapi/paths/components.yaml
Comment thread api/src/main/openapi/paths/components.yaml Outdated
@nscuro nscuro changed the title Issue 2049 : Improve component search performance with JDBI Improve component search performance with JDBI Apr 15, 2026
@nscuro nscuro merged commit ebf7d2e into main Apr 15, 2026
12 checks passed
@nscuro nscuro deleted the issue-2049-improve-component-search-performance branch April 15, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve performance of component search by coordinates

3 participants